package com.tool.btn;

import org.come.Frame.ZhuFrame;
import org.come.Jpanel.QiandaoListJpanel;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.time.LocalDate;

import javax.swing.*;

public class QianDaoBtn extends MoBanBtn {

    private int day = -1;
    private QiandaoListJpanel qiandaoListJpanel;

    public QianDaoBtn(String iconpath, int type, QiandaoListJpanel qiandaoListJpanel) {
        super(iconpath, type);
        this.qiandaoListJpanel = qiandaoListJpanel;
    }

    public QianDaoBtn(String iconpath, int type, Color[] colors, int num, int isup, QiandaoListJpanel qiandaoListJpanel) {
        super(iconpath, type, colors, num, isup);
        this.qiandaoListJpanel = qiandaoListJpanel;
    }

    public QianDaoBtn(String iconpath, int type, Color[] colors, Font font, String text, QiandaoListJpanel qiandaoListJpanel) {
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.qiandaoListJpanel = qiandaoListJpanel;
    }

    public QianDaoBtn(String iconpath, int type, Color[] colors, Font font, String text, int day, QiandaoListJpanel qiandaoListJpanel) {
        super(iconpath, type, colors);
        this.setText(text);
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.day = day;
        this.qiandaoListJpanel = qiandaoListJpanel;
    }




    @Override
    public void chooseyes() {

    }

    @Override
    public void chooseno() {

    }

    @Override
    public void nochoose(MouseEvent e) {
        if (day == -1) {
            if (qiandaoListJpanel.getDays().size()== QiandaoListJpanel.getCurrentMonthDay()){
                ZhuFrame.getZhuJpanel().addPrompt2("#89 您本月已签满！！！");
                return;
            }
            if (qiandaoListJpanel.getDays().contains(LocalDate.now().getDayOfMonth())) {
                ZhuFrame.getZhuJpanel().addPrompt2("#24 您今天已签到过了！！！");
            } else {
                //点击签到
                qiandaoListJpanel.setDay(qiandaoListJpanel.getDay() + 1);
                //向服务器发送签到信息
                SendMessageUntil.toServer(Agreement.getAgreement().qdAgreement("qd"));
            }

        }
        if (day > 0) {
            if (qiandaoListJpanel.getDays().size()<day){
                ZhuFrame.getZhuJpanel().addPrompt2("#24 少侠,请签到达到"+day+"天时再领取"+day+"天奖励！！！");
                return;
            }
            if (qiandaoListJpanel.getLqs().contains(day)) {
                ZhuFrame.getZhuJpanel().addPrompt2("#24 少侠,该奖励已经领取过了！！！");
            } else {
                SendMessageUntil.toServer(Agreement.getAgreement().qdAgreement("select=" + day));

            }
        }
    }
}
